package Snake;

import static org.junit.Assert.*;

import org.junit.Test;

public class CellTest {

	@Test
	public void testCellIntInt() {
		Cell c = new Cell(1, 2);
		assertNotNull(c);
	}

	@Test
	public void testCellIntIntInt() {
		Cell c = new Cell(1, 2, 3);
		assertNotNull(c);
	}

	@Test
	public void testGetX() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		int x = c.getX();
		assertNotNull(x);
		assertNotEquals(x, c.getY());
	}

	@Test
	public void testGetY() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		int y = c.getY();
		assertNotNull(y);
		assertNotEquals(c.getX(), y);
	}

	@Test
	public void testGetId() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		int id = c.getId();
		assertNotNull(id);
	}

	@Test
	public void testIsOccupied() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		boolean b = c.isOccupied();
		assertNotNull(b);
		assertFalse(b);
		c.setOccupied(true);
		assertTrue(c.isOccupied());
	}

	@Test(timeout=4000)
	public void testRequestCell() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		assertFalse(c.isOccupied());
		c.requestCell();
		c.setOccupied(true);
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					c.freeCell();
				} catch (InterruptedException e) {
					System.err.println("Interrupted Excepcion" + e.getMessage());
				}
			}
		}).start();
		c.isOccupied();
		c.requestCell();

	}

	@Test
	public void testFreeCell() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		assertFalse(c.isOccupied());
		c.setOccupied(true);
		c.freeCell();
		assertFalse(c.isOccupied());
	
	}

	@Test
	public void testSetId() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.setId(2);
		assertNotNull(c.getId());
	}

	@Test
	public void testSetOccupied() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		assertFalse(c.isOccupied());
		c.setOccupied(true);
		assertTrue(c.isOccupied());
	}

	@Test
	public void testToString() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.toString();
		assertNotNull(c);
	}
	
	@Test
	public void testSetX() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.setX(2);
		assertNotEquals(c.getX(), 1);
	}
	
	@Test
	public void testSetY() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.setY(1);
		assertNotEquals(2,c.getY());
	}
	
	@Test
	public void testHead() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.setHead(false);
		assertFalse(c.isHead());
	}
	
	@Test
	public void testJumpBoost() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.setJumpBoost(false);
		assertFalse(c.isJumpBoost());
	}
	
	@Test
	public void testToChangeDir() {
		Cell c = new Cell(1,2);
		assertNotNull(c);
		c.setToChangeDir(false);
		assertFalse(c.isToChangeDir());
	}

}
